<template>
  <scroll-view class="coupon-scroll" scroll-x="true">
    <view class="coupon-item" v-for="(item, index) in couponList" :key="index">
      <view class="coupon-content">
        <view class="price">
          <text v-if="item.discount_type != 1" :style="{ color: priceColor }"
            >￥</text
          >
          <text v-if="item.discount_type != 1" :style="{ color: priceColor }">{{
            item.sub_price | subStrToInt
          }}</text>
          <text
            v-if="item.discount_type == 1"
            :style="{ color: priceColor, fontSize: '38rpx' }"
            >{{ item.discount }}折</text
          >
        </view>
        <view class="coupon-info">
          <view class="coupon-title" :style="{ color: infoColor }">{{
            item.name
          }}</view>
          <view class="coupon-date" :style="{ color: infoColor }">{{
            item.expire_type != 1
              ? item.begintime + "-" + item.endtime
              : "领取" + item.expire_day + "天后失效"
          }}</view>
        </view>
        <view
          :class="['coupon-receive', item.is_receive == 1 ? 'has-receive' : '']"
          @click.stop="toGetCoupon(item)"
        >
          <view class="receive-inner">
            <view :style="{ color: btnColor }">{{ item.receive_content }}</view>
            <i class="iconfont icon-arrow-right"></i>
          </view>
        </view>
      </view>
      <view class="coupon-bg" :style="{ background: colorConfig.bgColor }">
      </view>
    </view>
  </scroll-view>
</template>

<script>
export default {
  props: {
    propsData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    couponList: {
      type: Array,
      default: [],
    },
  },

  computed: {
    colorConfig() {
      return this.propsData.params.colorConfig;
    },
    priceColor() {
      return this.propsData.params.colorConfig.priceColor;
    },
    infoColor() {
      return this.propsData.params.colorConfig.infoColor;
    },
    btnColor() {
      return this.propsData.params.colorConfig.btnColor;
    },
  },
  filters: {
    subStrToInt(val) {
      val = parseFloat(val);
      return val;
    },
  },
  methods: {
    toGetCoupon(item) {
      if (item.is_receive != 0) return;
      this.$emit("toGetCoupon", { item });
    },
  },
};
</script>

<style scoped lang="scss">
.coupon-scroll {
  width: 93.6%;
  margin: 0 auto;
  white-space: nowrap;
  .coupon-item {
    width: 100%;
    position: relative;
    height: 23.534vw;
    display: inline-block;
    padding: 0 3.2vw;
    margin-right: 3.2vw;
    .coupon-content {
      width: 98%;
      height: 92.39%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      position: absolute;
      left: 0;
      top: 0;
      z-index: 11;
      background-color: #ffffff;
      border: 1px solid #666666;
      padding-left: 6.97%;
      .price {
        display: flex;
        align-items: baseline;
        line-height: 1;
        text:first-child {
          font-size: 32rpx;
          color: #ec2827;
        }
        text:last-child {
          color: #ec2827;
          font-size: 60rpx;
          font-weight: bold;
        }
      }
      .coupon-info {
        width: 43.69%;
        position: absolute;
        left: 34.88%;
        top: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
        .coupon-title {
          font-size: 32rpx;
          font-family: PingFang SC;
          font-weight: bold;
          color: #ffffff;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .coupon-date {
          font-size: 28rpx;
          font-family: PingFang SC;
          font-weight: 400;
          color: #ffffff;
          margin-top: 5rpx;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      .coupon-receive {
        width: 22.09%;
        height: 72.94%;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
        z-index: 111;
        border-left: 1px solid #cccccc;
        .receive-inner {
          display: flex;
          justify-content: center;
          align-items: center;
          view {
            width: 30rpx;
            font-size: 24rpx;
            font-family: PingFang SC;
            font-weight: 400;
            color: #404040;
            white-space: pre-wrap;
            word-wrap: break-word;
            word-break: break-all;
          }
          .iconfont {
            font-size: 22rpx;
            color: #cccccc;
          }
        }
      }
      .has-receive {
        .receive-inner {
          view {
            width: inherit;
            color: #cccccc !important;
            text-align: center;
          }
        }
      }
    }
    .coupon-bg {
      width: 98%;
      height: 92.39%;
      position: absolute;
      right: 0;
      bottom: 0;
      z-index: 10;
    }
  }
  .coupon-item:last-child {
    margin-right: 0;
  }
}
</style>
